package com.immyc.user.server.service;

import com.immyc.model.entity.User;
import com.immyc.model.service.IUserService;
import com.immyc.user.server.UserServerService;
import com.immyc.util.IdGen;
import com.immyc.util.PasswordEncoder;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

/**
 * @Description:
 * @Author: mayc
 * @Date: 2019/05/15 16:00
 */
@Service
public class UserServerServiceImpl implements UserServerService {

    @Autowired
    private IUserService userServiceImpl;

    @Override
    public String getMsg(String msg) {
        return null;
    }

    @Override
    public void addUser(User user) {
        user.setId(IdGen.getId());
        String salt = PasswordEncoder.salt();
        if (StringUtils.isBlank(user.getCertification())) {
            user.setCertification("123456");
        }
        user.setCertification(PasswordEncoder.pwdRule(user.getCertification(), salt));
        user.setSalt(salt);
        user.setCreateTime(System.currentTimeMillis());
        user.setUpdateTime(System.currentTimeMillis());
        user.setStatus(0);
        this.userServiceImpl.save(user);
    }

    @Override
    public void update(User user) {

    }

    @Override
    public List<User> findUsers() {
        if (this.userServiceImpl == null) {
            System.out.println("fk");
        }
        return this.userServiceImpl.list();
    }
}
